//
//  CacheTool.m
//  Command
//
//  Created by Hechun on 2020/11/7.
//

#import "StorageTool.h"

static NSString * const kStorageToolKey = @"kStorageToolKey";

@implementation StorageTool

+ (void)saveNewsId:(NSString *)newsId {
    NSMutableArray *array = [[NSUserDefaults standardUserDefaults] objectForKey:kStorageToolKey];
    if (array && [array isKindOfClass:[NSArray class]]) {
        array = [array mutableCopy];
    } else {
        array = [NSMutableArray array];
    }
    
//    for (int i = 0; i < 10000000; i ++) {
//        [array addObject:[NSNumber numberWithInt:i]];
//    }
    // 内存是有限制的
    // 缓存设计
    
    if ([newsId isKindOfClass:[NSString class]] && ![array containsObject:newsId]) {
        [array addObject:newsId];
        [[NSUserDefaults standardUserDefaults] setValue:array forKey:kStorageToolKey];
    }
}

+ (BOOL)isContainNewsId:(NSString *)newsId {
    BOOL isContain = NO;
    NSMutableArray *array = [[NSUserDefaults standardUserDefaults] objectForKey:kStorageToolKey];
    if (array && [array isKindOfClass:[NSArray class]] && [newsId isKindOfClass:[NSString class]]) {
        if ([array containsObject:newsId]) {
            isContain = YES;
        } else {
            isContain = NO;
        }
    } else {
        isContain = NO;
    }
    
    return isContain;
}

@end
